package com.api.organization.adduser;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IOrganizationApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(locations = { "classpath:/organization/organization-context.xml" })
public class AddUserAdministrator extends AbstractApiTest {

	private static final long DEFAULT_STORAGE = 2097152;

	@Value("#{org_editOrganization[administrator].appId}")
	private String userId;

	@Value("#{org_editOrganization[administrator].password}")
	private String userPassword;

	private String userAddedUrn = "";

	@BeforeClass
	public void setUpVariables() {

		getApi().login(userId, userPassword);
	}

	@Test
	public synchronized void testAddUser() throws ZyncroApiException {

		String name = "editorganization";
		String lastname = "to-add12";
		String email = name + "-" + lastname + "@yopmail.com";
		String password = "123456";

		long storage = DEFAULT_STORAGE;
		boolean canPublishCorporateFeed = false;
		boolean canCreateGroups = true;
		boolean canCreateDepartments = false;
		boolean isAdministrator = false;

		this.userAddedUrn = getApi().getService(IOrganizationApiService.class).addUser(name, lastname, email, password, storage,
				canPublishCorporateFeed, canCreateGroups, canCreateDepartments, isAdministrator, null, null);

		Assert.assertNotNull(this.userAddedUrn);
	}

	@AfterClass
	public void restoreValues() throws ZyncroApiException {

		getApi().getService(IOrganizationApiService.class).deleteUser(userAddedUrn, null);
	}
}
